1. /* sdcrec_e.cpp by K.Tsuru */
  2. // function ID 3507 DRADIX, constant
  3. /*****************************************
  4. SDouble class
  5. reciprocal of the base of natural logarithm
  6. exp(-1)
  7. *****************************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. class BSRecExp1 : public BinarySplittingA1C<SLong> {
  12. public:
  13. BSRecExp1(long L, long prec) : BinarySplittingA1C<SLong>(L, prec) {}
  14. void setAC(long k, SLong& a, SLong& c) {
  15. a.SetSmall((k&1) ? 1 : (-1)); // A(k) = (-1)^(k-1)
  16. c.SetInt(k + 1); // C(k) = k + 1;
  17. }
  18. SDouble getValue() {
  19. putTogether();
  20. return BinarySplittingA1C<SLong>::getValue() + 1.0;
  21. }
  22. };
  23. static SDouble* recE = NULL;//keep in the static memory
  24. static uint recE_size = 0;
  25. void RecEFree(){ //free the memory of recE
  26. if(recE_size == 0) return;
  27. delete recE; recE = NULL; recE_size = 0;
  28. }
  29. /********************************************************
  30. 1/e If "invE=true", it returns "1/E()" else evaluates by
  31. the "class BSRecExp1" above for test "RecE()*E()=1" ?.
  32. *********************************************************/
  33. SDouble RecE(bool invE){
  34. SDouble temp;
  35. uint rE_size = temp.MaxSize();
  36. if( recE_size < rE_size ){
  37. if(recE == NULL) recE = new SDouble;
  38. }
  39. if(invE) {
  40. temp = E();
  41. *recE = DReciprocal(temp);
  42. } else {
  43. long prec = long(temp.EffFig() + temp.Hidden()) * DFIGURES;
  44. long L = upToExpSeries(prec, 0.0);
  45. BSRecExp1 re(L, prec);
  46. *recE = re.getValue();
  47. }
  48. recE_size = rE_size;
  49. return *recE;
  50. }

sdcrec_e.cpp : last modifiled at 2017/06/23 10:01:52(1,519 bytes)
created at 2017/10/07 10:21:15
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).